<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="./Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="./Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link href="./Public/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">
	    <link rel="shortcut icon" href="./Public/Admin/Flat/img/favicon.ico">
	 	<script type="text/javascript" src="Public/Admin/uploadify/jquery-1.8.2.min.js"></script>
	 	<script>
	 		$(function(){
	 			$(".add").click(function(){
	 				var glstock=$('#glstock').val();

	 				var glnum=$('#glnum').val();
	 				var gid="{{Q('get.gid')}}";
	 				var obj = $("select option:selected");
	 			
	 				var combo = new Array();
	 				for(var i=0;i<obj.length;i++){
	 					
	 					combo.push(obj[i].value);

	 				}
	 				// console.log(combo);
	 				$.ajax({
	 					type:"post",
	 					url:"{{U('GoodsList/add')}}",
	 					data:{combo: combo,glstock:glstock,glnum:glnum,goods_gid:gid},
	 					dataType:'json',
	 					success:function(phpData){
	 						var data=phpData;
	 						var attr = '';
		 						attr+='<tr>';
		 						attr+='<td>'+data.glid+'</td>';
		 							$.each(data.value, function(k,v) { 
		 								console.log(v);
		 								$.each(v, function(k,v){
										attr += '<td>'+v.gtvalue+'</td>';
										})
									 });
		 						attr+='<td>'+data.glstock+'</td><td>'+data.glnum+'</td>';
		 						attr+='<td><a href="" class="btn btn-sm btn-warning">编辑</a>  <a href="" class="btn btn-sm btn-danger">删除</a></td></tr>';
		 						
		 						$("#attra").before(attr);
	 					}
	 				})

	 				
	 			})
	 		})
	 	</script>
	</head>
	<body>
		<table class="table table-hover" >
			<tr class="active">
			  <th width="30">glid</th>
			  
			  {{foreach from="$data" value="$v"}}
			  	 <th width="200">{{$v['taname']}}</th>
			  {{endforeach}}
			  <th>库存</th>
              <th>货号</th>
			  <th width="200">操作</th>
			  
			 
			</tr>

			{{foreach from="$listData" value="$v"}}
			<tr >
			
				<td>{{$v['glid']}}</td>
				{{foreach from="$v['value']" value="$value"}}
				<td>{{$value['gtvalue']}}</td>
				{{endforeach}}
				<td>{{$v['glstock']}}</td>
				<td>{{$v['glnum']}}</td>
				
            
				<td>
					<a href="{{U('GoodsList/edit',array('glid'=>$v['glid']))}}" class="btn btn-sm btn-warning">编辑</a>
					<a href="javascript: if(confirm('确定删除吗？')) location.href='{{U('GoodsList/del',array('glid'=>$v['glid']))}}'" class="btn btn-sm btn-danger">删除</a>
				</td>
			</tr>
			{{endforeach}}
			
			<tr id='attra'>	
			 	<td width="100">添加商品</td>
			 		{{foreach from="$data" value="$v"}}
				 		<td>
				 		<select name="" class="select" id="id" gid="{{$v['goods_gid']}}">
			 				<option value="">请选择</option>
			 				{{foreach from="$v['value']" value="$value" }}
			 					
			 			   		<option id="id" value="{{$value['gtid']}}" >{{$value['gtvalue']}}</option>
			 					
			 				{{endforeach}}
			 			</select>

			 		</td>
			 		{{endforeach}}
			 	<td>
            		<input type="text" name="glstock" id="glstock" >
		        </td>
		        <td>
		            <input type="text" name="glnum" id="glnum">
		        </td>
				<td>
					<input type="submit" value="确认添加" class="btn btn-primary btn-block btn-large add" />
				</td>
			</tr>
		</table>

	</body>
</html>
